import axios from 'axios';

// 使用在 main.js 中设置的全局 API_BASE_URL
const API_BASE_URL = `${window.API_BASE_URL || 'http://localhost:3002'}/api`;

const api = axios.create({
  baseURL: API_BASE_URL,
  headers: {
    'Content-Type': 'application/json',
  },
});

// 获取所有品牌信息
export const getBrands = () => api.get('/brands');

// 根据品牌名称获取品牌详细信息（包括所有配置）
export const getBrandByName = (brandName) => api.get(`/brands/${brandName}`);

// 根据品牌名称和配置名称获取特定配置的详细信息
export const getConfigByBrandAndName = (brandName, configName) => api.get(`/brands/${brandName}/configs/${configName}`);

// 创建新品牌
export const createBrand = (brandData) => api.post('/brands', brandData);

// 为品牌添加新配置
export const createConfig = (brandName, configData) => api.post(`/brands/${brandName}/configs`, configData);

// 更新品牌配置
export const updateConfig = (brandName, configName, configData) => api.put(`/brands/${brandName}/configs/${configName}`, configData);

// 删除品牌配置
export const deleteConfig = (brandName, configName) => api.delete(`/brands/${brandName}/configs/${configName}`);

export default api;